<%@include  file="/WEB-INF/header.jsp"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<script>
//删除场地信息
function delStu(stuname){
	if(confirm("是否删除该学员信息?")){
	//ajax异步请求，三个参数，第一个地址,第二个控制层username、页面的username，第三个参数function函数
	$.post("${pageContext.request.contextPath}/stu/delStu.action",{"stuname":stuname},
	//回调函数，得到的是json格式，controller层
		function(data){
	            if(data =="OK"){
	                alert("删除学员信息成功");
	                window.location.reload();
	            }else{
	                alert("删除学员信息失败");
	                window.location.reload();
	            }
	        });
	    }
	}
	
	
//通过id获取修改的书籍信息
function editStu(id) {
	  $.ajax({
	        type:"get",
	        url:"<%=basePath%>stu/getStuById.action",
	        data:{"student_id":id},
	        success:function(data) {
	        	$("#edit_stu_id").val(data.id);
	            $("#edit_stuName").val(data.name);
	            $("#edit_stuIDcard").val(data.idcard);
	            $("#edit_stuAge").val(data.age);
	            $("#edit_stuTel").val(data.telephone);
	            $("#edit_stuAddress").val(data.address);
	          	 if(data.subject_1 != "" && data.subject_1 != null){
	            	$("#edit_stuSubject1").val(data.subject_1);
	            }
	            if(data.subject_2 != "" && data.subject_2 != null){
	            	$("#edit_stuSubject2").val(data.subject_2);
	            }
	            if(data.subject_3 != "" && data.subject_3 != null){
	            	$("#edit_stuSubject3").val(data.subject_3);
	            }
	            if(data.subject_4 != "" && data.subject_4 != null){
	            	$("#edit_stuSubject4").val(data.subject_4);
	            }
	            $("#edit_stuStatus").val(data.status);
	            
	           
	        }
	    });
}

function updateStu() {
	
	$.post("${pageContext.request.contextPath}/student/update.action",$("#edit_student_form").serialize(),function(data){
		if(data =="OK"){
			alert("修改学员信息成功");
			window.location.reload();
		}else{
			alert("修改学员信息失败");
			window.location.reload();
		}
	});
}

</script>
<div id="page-wrapper">
	 <div class="row">
			<div class="col-lg-12">
				<h1 class="page-header">学员信息管理</h1>
			</div>
	</div>
	<div class="panel panel-default">
		<div class="panel-body">
			<form class="form-inline" method="get" style="float:left"  
			      action="${pageContext.request.contextPath }/stu/getStuByName.action">
				<div class="form-group">
					<label for="placeName">查询学员信息</label>
					&nbsp;&nbsp; 
					<input type="text" class="form-control" id="name" 
					                   value="${name}" name="name" />
				
				</div>
				&nbsp;&nbsp;
				<button type="submit" class="btn btn-success">查询</button>
			</form>
			
			<form class="form-inline" style="float:left" 
			      action="${pageContext.request.contextPath }/student/getAllstudent.action">
			      &nbsp;&nbsp;
				   <button type="submit" class="btn btn-warning">返回</button>
			</form>
			
			
			
		</div>
	</div>
	<table class="table table-striped">
	<thead>
    <tr>
      <th>姓名</th>
      <th>身份证</th>
      <th>年龄</th>
      <th>电话</th>
	  <th>住址</th>
   	  <th>科目一</th>
      <th>科目二</th>
      <th>科目三</th>
      <th>科目四</th>
      <th>考试进度</th>
   	
    </tr>
  </thead>
  <tbody>
    <c:forEach items="${Stu_list}" var="s">
      <tr>
      <td>${s.name}</td>
      <td>${s.IDcard}</td>
      <td>${s.age}</td>
      <td>${s.telephone}</td>
      <td>${s.address}</td>
      <td>${s.subject_1 == '未考试'?'未考试':s.subject_1 =='通过'?'通过':'未通过'}</td>
      <td>${s.subject_2 == '未考试'?'未考试':s.subject_2 =='通过'?'通过':'未通过'}</td>
      <td>${s.subject_3 == '未考试'?'未考试':s.subject_3 =='通过'?'通过':'未通过'}</td>
      <td>${s.subject_3 == '未考试'?'未考试':s.subject_4 =='通过'?'通过':'未通过'}</td>
      <td>${s.status}</td>
      
     
      <td>
	   <a href="#" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#stuEditDialog" onclick= "editStu(${s.id})">修改</a>
	   	<a href="#" class="btn btn-danger btn-xs" onclick="delStu('${s.name}')">删除</a>
		      <!-- 按钮增加 /onlinck事件，方法名(参数为字符串需用'') -> js脚本 -->
	 </td>
      	
      
    </tr>
  </c:forEach>


  </tbody>
  </table>
</div>
<!-- 修改课程信息模态框 -->
<div class="modal fade" id="stuEditDialog" data-backdrop="static" tabindex="-1" role="dialog"
	aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title" id="myModalLabel">修改学员基本信息</h4>
			</div>
			<div class="modal-body">
				<form class="form-horizontal" id="edit_student_form">
                    <input type="hidden" id="edit_stu_id" name="id"/>
					<div class="form-group" id="form_user">
						<label for="edit_stuName" style="float:left;padding:7px 15px 0 27px;">学员姓名</label> 
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_stuName" placeholder="学员姓名" name="name" required/>
						</div>
					</div>
					<div class="form-group" id="form_user">
						<label for="edit_stuIDcard" style="float:left;padding:7px 15px 0 27px;">身份证号</label> 
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_stuIDcard" placeholder="身份证号" name="IDcard" required/>
						</div>
					</div>
					<div class="form-group" id="form_user">
						<label for="edit_stuAge" style="float:left;padding:7px 15px 0 27px;">学员年龄</label> 
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_stuAge" placeholder="学员年龄" name="age" required/>
						</div>
					</div>
					<div class="form-group" id="form_user">
						<label for="edit_stuTel" style="float:left;padding:7px 15px 0 27px;">学员电话</label> 
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_stuTel" placeholder="学员电话" name="telephone" required/>
						</div>
					</div>
					<div class="form-group" id="form_user">
						<label for="edit_stuAddress" style="float:left;padding:7px 15px 0 27px;">学员住址</label> 
						<div class="col-sm-10">
							<input type="text" class="form-control" id="edit_stuAddress" placeholder="学员住址" name="address" required/>
						</div>
					</div>
					<div class="form-group" id="form_user">
						<label for="edit_stuSubject1" style="float:left;padding:7px 15px 0 27px;">科一考试情况</label> 
						<div class="col-sm-10" style="width:470px;">
							<select	class="form-control" id="edit_stuSubject1" name="subject_1">
								<option value ="未考试" selected>
								未考试					
								</option>
								<option value="通过" >
								通过								
								</option>
								<option value="未通过" >
								未通过								
								</option>
							</select>
						</div>
					</div>
					<div class="form-group" id="form_user">
						<label for="edit_stuSubject2" style="float:left;padding:7px 15px 0 27px;">科二考试情况</label> 
						<div class="col-sm-10" style="width:470px;">
							<select	class="form-control" id="edit_stuSubject2" name="subject_2">
								<option value ="未考试" selected>
								未考试					
								</option>
								<option value="通过" >
								通过								
								</option>
								<option value="未通过" >
								未通过								
								</option>
							</select>
						</div>
					</div>
					<div class="form-group" id="form_user">
						<label for="edit_stuSubject3" style="float:left;padding:7px 15px 0 27px;">科三考试情况</label> 
						<div class="col-sm-10" style="width:470px;">
							<select	class="form-control" id="edit_stuSubject3" name="subject_3">
								<option value ="未考试" selected>
								未考试					
								</option>
								<option value="通过" >
								通过								
								</option>
								<option value="未通过" >
								未通过								
								</option>
							</select>
						</div>
					</div>
					<div class="form-group" id="form_user">
						<label for="edit_stuSubject4" style="float:left;padding:7px 15px 0 27px;">科四考试情况</label> 
						<div class="col-sm-10" style="width:470px;">
							<select	class="form-control" id="edit_stuSubject4" name="subject_4">
								<option value ="未考试" selected>
								未考试					
								</option>
								<option value="通过" >
								通过								
								</option>
								<option value="未通过" >
								未通过								
								</option>
							</select>
						</div>
					</div>
					<div class="form-group" id="form_user">
						<label for="edit_stuStatus" style="float:left;padding:7px 15px 0 27px;">考试进度</label> 
						<div class="col-sm-10">
							<select	class="form-control" id="edit_stuStatus" name="status">
								<option value ="未考试" selected>
								未考试				
								</option>
								<option value="通过科目一" >
								通过科一							
								</option>
								<option value="通过科目二" >
								通过科二							
								</option>
								<option value="通过科目三" >
								通过科三						
								</option>
								<option value="通过科目四" >
								通过科四					
								</option>
							</select>
						</div>
					</div>	
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				<button type="button" class="btn btn-success" onclick="updateStu()">修改学员信息</button>
			</div>
		</div>
	</div>
	
</div>


<%@include  file="/WEB-INF/footer.jsp"%>